﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sherwood.SignOn.Server.Models.Services;

namespace Sherwood.SignOn.Server.Tests.UserAccountTests
{
    [TestClass]
    public class RepositoryTests : TestBase
    {
        [TestMethod]
        public void UserSearchTest()
        {
            //Assemble
            IUserAccount user1 = TestHelper.RegisterValidDummyUser("NewUser", "someone@somewhere.sherwood.local","John","Brown");
            IUserAccount user2 = TestHelper.RegisterValidDummyUser("AnotherUser", "user2@somewhereelse.sherwood.local","Joe","Bloggs");
            IUserAccount user3 = TestHelper.RegisterValidDummyUser("YetAnother", "humpty@somewhereelse.sherwood.local", "Humpty", "van Dumpty");
            

            //Act (single word search)
            IEnumerable<IUserAccount> result1 = Data.UserAccounts.GetUserAccounts("user");
            IEnumerable<IUserAccount> result2 = Data.UserAccounts.GetUserAccounts("NewUser");
            IEnumerable<IUserAccount> result3 = Data.UserAccounts.GetUserAccounts("SomewhereElse");
            IEnumerable<IUserAccount> result4 = Data.UserAccounts.GetUserAccounts("Sherwood");
            IEnumerable<IUserAccount> result5 = Data.UserAccounts.GetUserAccounts("blabla");
            IEnumerable<IUserAccount> result6 = Data.UserAccounts.GetUserAccounts("joe");
            IEnumerable<IUserAccount> result7 = Data.UserAccounts.GetUserAccounts("brown");

            //Act (multiple name search)
            IEnumerable<IUserAccount> result8 = Data.UserAccounts.GetUserAccounts("john brown");
            IEnumerable<IUserAccount> result9 = Data.UserAccounts.GetUserAccounts("joe brown");

            IEnumerable<IUserAccount> result10 = Data.UserAccounts.GetUserAccounts("humpty van dumpty");
            IEnumerable<IUserAccount> result11 = Data.UserAccounts.GetUserAccounts("humpty dumpty");
            IEnumerable<IUserAccount> result12 = Data.UserAccounts.GetUserAccounts("dumpty humpty");
            IEnumerable<IUserAccount> result13 = Data.UserAccounts.GetUserAccounts("dumpty, humpty van");
            IEnumerable<IUserAccount> result14 = Data.UserAccounts.GetUserAccounts("van dumpty, humpty");
            IEnumerable<IUserAccount> result15 = Data.UserAccounts.GetUserAccounts("hump van dump");

            IEnumerable<IUserAccount> result16 = Data.UserAccounts.GetUserAccounts("");

            //Assert
            Assert.IsTrue(result1.Count() == 2);
            Assert.IsTrue(result2.Count() == 1);
            Assert.IsTrue(result3.Count() == 2);
            Assert.IsTrue(result4.Count() == 3);
            Assert.IsTrue(result5.Count() == 0);
            Assert.IsTrue(result6.Count() == 1);
            Assert.IsTrue(result7.Count() == 1);

            Assert.IsTrue(result8.Count() == 1);
            Assert.IsTrue(result9.Count() == 0, "Multiple names must match fields on a single person.");

            Assert.IsTrue(result10.Count() == 1);
            Assert.IsTrue(result11.Count() == 1);
            Assert.IsTrue(result12.Count() == 1);
            Assert.IsTrue(result13.Count() == 1);
            Assert.IsTrue(result14.Count() == 1);
            Assert.IsTrue(result15.Count() == 1);

            Assert.IsTrue(result16.Count() == 0,"Empty string should not return any search results");

        }
    }
}
